package com.ying.dogying.im;

import com.ying.dogying.entity.Const;
import com.ying.dogying.im.handler.MessageHandler;
import com.ying.dogying.im.handler.impl.ChatMessageHandler;
import com.ying.dogying.im.handler.impl.PingMessageHandler;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 初始化消息处理器工厂
 */
public class MessageHandlerFactory {

	private static Logger log = LoggerFactory.getLogger(MessageHandlerFactory.class);
    private static Map<String, MessageHandler> handlerMap = new HashMap<>();

    /**
     * 预先初始化消息处理器
     */
    public static void init(){

        handlerMap.put(Const.IM_MESS_TYPE_CHAT, new ChatMessageHandler());
        handlerMap.put(Const.IM_MESS_TYPE_PING, new PingMessageHandler());

        log.info("handler factory init !!");
    }

    public static MessageHandler getMessageHandler(String type) {
        return handlerMap.get(type);
    }

}
